//
//  UIView+JRMASShorthandAdditions.h
//  JRMASonry
//
//  Created by Jonas Budelmann on 22/07/13.
//  Copyright (c) 2013 Jonas Budelmann. All rights reserved.
//

#import "View+JRMASAdditions.h"

#ifdef JRMAS_SHORTHAND

/**
 *	Shorthand view additions without the 'JRMAS_' prefixes,
 *  only enabled if JRMAS_SHORTHAND is defined
 */
@interface JRMAS_VIEW (JRMASShorthandAdditions)

@property (nonatomic, strong, readonly) JRMASViewAttribute *left;
@property (nonatomic, strong, readonly) JRMASViewAttribute *top;
@property (nonatomic, strong, readonly) JRMASViewAttribute *right;
@property (nonatomic, strong, readonly) JRMASViewAttribute *bottom;
@property (nonatomic, strong, readonly) JRMASViewAttribute *leading;
@property (nonatomic, strong, readonly) JRMASViewAttribute *trailing;
@property (nonatomic, strong, readonly) JRMASViewAttribute *width;
@property (nonatomic, strong, readonly) JRMASViewAttribute *height;
@property (nonatomic, strong, readonly) JRMASViewAttribute *centerX;
@property (nonatomic, strong, readonly) JRMASViewAttribute *centerY;
@property (nonatomic, strong, readonly) JRMASViewAttribute *baseline;
@property (nonatomic, strong, readonly) JRMASViewAttribute *(^attribute)(NSLayoutAttribute attr);

#if TARGET_OS_IPHONE || TARGET_OS_TV

@property (nonatomic, strong, readonly) JRMASViewAttribute *leftMargin;
@property (nonatomic, strong, readonly) JRMASViewAttribute *rightMargin;
@property (nonatomic, strong, readonly) JRMASViewAttribute *topMargin;
@property (nonatomic, strong, readonly) JRMASViewAttribute *bottomMargin;
@property (nonatomic, strong, readonly) JRMASViewAttribute *leadingMargin;
@property (nonatomic, strong, readonly) JRMASViewAttribute *trailingMargin;
@property (nonatomic, strong, readonly) JRMASViewAttribute *centerXWithinMargins;
@property (nonatomic, strong, readonly) JRMASViewAttribute *centerYWithinMargins;

#endif

- (NSArray *)makeConstraints:(void(^)(JRMASConstraintMaker *make))block;
- (NSArray *)updateConstraints:(void(^)(JRMASConstraintMaker *make))block;
- (NSArray *)remakeConstraints:(void(^)(JRMASConstraintMaker *make))block;

@end

#define JRMAS_ATTR_FORWARD(attr)  \
- (JRMASViewAttribute *)attr {    \
    return [self JRMAS_##attr];   \
}

@implementation JRMAS_VIEW (JRMASShorthandAdditions)

JRMAS_ATTR_FORWARD(top);
JRMAS_ATTR_FORWARD(left);
JRMAS_ATTR_FORWARD(bottom);
JRMAS_ATTR_FORWARD(right);
JRMAS_ATTR_FORWARD(leading);
JRMAS_ATTR_FORWARD(trailing);
JRMAS_ATTR_FORWARD(width);
JRMAS_ATTR_FORWARD(height);
JRMAS_ATTR_FORWARD(centerX);
JRMAS_ATTR_FORWARD(centerY);
JRMAS_ATTR_FORWARD(baseline);

#if TARGET_OS_IPHONE || TARGET_OS_TV

JRMAS_ATTR_FORWARD(leftMargin);
JRMAS_ATTR_FORWARD(rightMargin);
JRMAS_ATTR_FORWARD(topMargin);
JRMAS_ATTR_FORWARD(bottomMargin);
JRMAS_ATTR_FORWARD(leadingMargin);
JRMAS_ATTR_FORWARD(trailingMargin);
JRMAS_ATTR_FORWARD(centerXWithinMargins);
JRMAS_ATTR_FORWARD(centerYWithinMargins);

#endif

- (JRMASViewAttribute *(^)(NSLayoutAttribute))attribute {
    return [self JRMAS_attribute];
}

- (NSArray *)makeConstraints:(void(^)(JRMASConstraintMaker *))block {
    return [self JRMAS_makeConstraints:block];
}

- (NSArray *)updateConstraints:(void(^)(JRMASConstraintMaker *))block {
    return [self JRMAS_updateConstraints:block];
}

- (NSArray *)remakeConstraints:(void(^)(JRMASConstraintMaker *))block {
    return [self JRMAS_remakeConstraints:block];
}

@end

#endif
